{extend name="layout" /}
{block name="content"}
<style>
    #container{
        padding: 0px;
        border-radius:0px;
        border-width:0px;
    }
</style>
<form class="layui-form seller-alone-form" action="" method="post">
    <input type="hidden" id="id" name="id" value="{$data.id}">

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>标题：</label>
        <div class="layui-input-block">
            <input type="text" name="title" required lay-verify="required" autocomplete="off" placeholder="请输入标题"
                   class="layui-input" value="{$data.title}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>作者：</label>
        <div class="layui-input-block">
            <input type="text" name="author" required lay-verify="required" autocomplete="off" placeholder="请输入作者"
                   class="layui-input" value="{$data.author}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">热度：</label>
        <div class="layui-input-block">
            <input type="text" name="sort" autocomplete="off" placeholder="热度越高，排名越靠前"
                   class="layui-input" value="{$data.sort}">
        </div>
    </div>



    <div class="layui-form-item layui-form-text" >
        <label class="layui-form-label">文章内容：</label>
        <div class="layui-input-block" style="z-index: 1">
            <textarea id="container" name="content" style="width:100%;height:300px;" type="text/plain" class="layui-textarea">{$data.content}</textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit lay-filter="add_article">保存</button>
            <button onclick="javascript:history.back(-1);" type="reset" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>

</form>

<script>
    //Demo
    layui.use(['form','laydate'], function(){
        var laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#date',
            trigger: 'click' //自动弹出控件的事件，采用click弹出
        });
        var form = layui.form;
        //监听提交
        form.on('submit(add_article)', function(data){
            JsPost("{:url('Article/edit')}", data.field, function(res){
                if(res.status){
                    layer.msg(res.msg, {time: 1300},function(){
                        window.location.href = "{:url('Article/index')}";
                    });
                }else{
                    layer.msg(res.msg);
                }
            })
        });
    });


    var _editor = UE.getEditor("edit_image", {
        initialFrameWidth: 800,
        initialFrameHeight: 300,
    });


    _editor.ready(function() {
        _editor.hide();
        _editor.addListener('beforeInsertImage', function(t, arg) {
            if (arg.length > 1) {
                layer.msg("最多只能选择1张图片，请重新选择");
                return false;
            }else {
                $("#cover").attr("value",arg[0].src);
                $("#img_preview").attr("src",arg[0].src);
            }
            return true;
        });
    });


    //上传dialog
    function upImage() {

        var myImage = _editor.getDialog("insertimage");
        myImage.open();
    }

</script>

<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>
<textarea id="edit_image" style="display: none;"></textarea>
{/block}